package com.yanqu.road.server.cmd.cricket;

import com.yanqu.road.entity.enums.eSystemId;
import com.yanqu.road.message.YanQuMessage;
import com.yanqu.road.pb.cricket.CricketProto;
import com.yanqu.road.server.cmd.base.AbstractCommand;
import com.yanqu.road.server.command.Cmd;
import com.yanqu.road.server.gameplayer.GamePlayer;
import com.yanqu.road.server.gameplayer.module.cricket.CricketModule;
import com.yanqu.road.server.manger.config.SystemOpenMgr;
import com.yanqu.road.server.protocol.ClientProtocol;
import com.yanqu.road.server.protocol.GameErrorCode;
import com.yanqu.road.server.protocol.GameProtocol;

@Cmd(code = GameProtocol.S_CRICKET_LEARN_PARTON_SKILL, desc = "激活、突破虫师技能")
public class CricketLearnPartonSkillCmd extends AbstractCommand {

    private int patronsId;

    private int skillId;

    @Override
    public boolean parseData(YanQuMessage packet) throws Exception {
        CricketProto.CricketLearnPartonSkillReqMsg reqMsg = CricketProto.CricketLearnPartonSkillReqMsg.parseFrom(packet.getBytes());
        patronsId = reqMsg.getPatronsId();
        skillId = reqMsg.getSkillId();
        return true;
    }

    @Override
    public void execute(GamePlayer player, YanQuMessage packet) throws Exception {
        if (!SystemOpenMgr.systemOpen(player, eSystemId.Cricket.getValue())) {
            ret = GameErrorCode.E_CRICKET_NOT_OPEN;
        } else {
            ret = player.getModule(CricketModule.class).learnPartonSkill(patronsId, skillId);
        }
    }

    @Override
    public void sendData(GamePlayer player) {
        if (ret != 0) {
            CricketProto.CricketLearnPartonSkillRespMsg.Builder respMsg = CricketProto.CricketLearnPartonSkillRespMsg.newBuilder();
            respMsg.setRet(ret);
            player.sendPacket(ClientProtocol.U_CRICKET_LEARN_PARTON_SKILL, respMsg);
        }
    }
}
